package com.github.kezhenxu94.acs;

import java.util.Properties;
import java.util.logging.Logger;

import com.github.kezhenxu94.acs.common.Environment;
import com.github.kezhenxu94.acs.math.Matrix;

/**
 * Created by kezhenxu at Dec 18, 2016
 *
 * @author kezhenxu (kezhenxu94@163.com)
 */
public class NaiveAntClusterer {
	private Logger logger = Logger.getLogger(NaiveAntClusterer.class.getName());

	protected Environment	environment;
	protected AntColony		antColony;

	public NaiveAntClusterer(final Environment environment) {
		this.environment = environment;
		this.antColony = new AntColony(environment);
	}

	public void cluster() {
		ClusterSolutions solutions = new ClusterSolutions(environment);
		for (int iteration = 0; iteration < environment.getMaxIteration(); iteration++) {
			for (int antIndex = 0; antIndex < environment.getColonySize(); antIndex++) {
				Solution solution = (Solution) antColony.getAgent(antIndex).construct();
				logger.info("Ant " + antIndex + " iteration " + iteration + ": " + solution);
				solutions.setSolution(antIndex, solution);
			}
		}
		new Fitness().evaluate(solutions, environment.getDataSet());
	}

	public Environment getEnvironment() {
		return environment;
	}

	public void setEnvironment(Environment environment) {
		this.environment = environment;
	}

	public static void main(String[] args) {
		Properties properties = new Properties();
		Environment environment = new Environment(properties);
		environment.setDataSet(Matrix.random(10, 4));
		environment.init();
		NaiveAntClusterer clusterer = new NaiveAntClusterer(environment);
		clusterer.cluster();
	}
}
